<template>
  <a-dialog :title="customTitle? customTitle :title" :visible.sync="show" width="800px" @confirm="confirm" @cancel="cancel" :show-confirm="status !=='info'">
    <a-form ref="aform" :status="status" :form-config="formConfig" :form="form_" :disabled="disabled" @confirm="doConfirm"></a-form>
  </a-dialog>
</template>

<script>
import aDialog from './a-dialog.vue'
import aForm from  './a-form.vue'
export default {
  components:{aForm, aDialog},
  props:{
    formConfig:{
      type:Object,
      default:()=>{}
    },
    form:{
      type:Object,
      default:()=>{}
    },
    status:{
      type:String,
      default:'add'
    },
    disabled:{
      type:Boolean,
      default:false
    },
    customTitle:undefined
  },
  data(){
    return {
      show:true,
      form_:{},
      formConfig_:{},
      type:this.isEdit
    }
  },
  computed:{
    title(){
      if(this.status === 'add') return '新增'
      if(this.status === 'edit') return '编辑'
      if(this.status === 'info') return '详情'
    }
  },
  methods:{
    confirm(){
      this.$refs.aform.confirm()
    },
    doConfirm(e){
      this.$emit('confirm',e)
    },
    cancel(){
      this.$emit('cancel')
    }
  },
  watch:{
    form:{
      handler(e){
        console.log('formData :',e)
        if(e){
          this.form_ = e
        }
      },
      immediate:true
    }
  }

}
</script>

<style scoped lang="scss">

</style>
